<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/11/30
 * Time: 16:22
 */
namespace app\common\helper;

use app\common\config\company_config;

class company_helper
{
    /**
     * 获取公司id
     * @return int
     */
    public static function get_company_id()
    {
        static $company_id = null;
        if ( $company_id !== null ) return $company_id;

        $subdomain = setting_helper::get_subdomain();
        if ($subdomain) {
            $company_id = open_card_helper::get_company_id_by_domain($subdomain);
        }

        if (!$company_id) {
            if (isset($_SESSION['company_id']) && $_SESSION['company_id']) {
                $company_id = $_SESSION['company_id'];
            } else {
                $company_id = user_helper::get_user_company_id();
            }
        }

        return isset($company_id) ? $company_id : 0 ;
    }

    /**
     * 获取公司等级对应的最大公众号数量
     * @param unknown $company_id
     * @return multitype:string
     */
    public static function get_company_level_total($company_id)
    {
        $company_info = _uri('company', ['id' => $company_id]);
        return company_config::$company_level[$company_info['level']];
    }

}